<ui:composition template="/WEB-INF/template/template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions"
                xmlns:sgbd="http://java.sun.com/jsf/composite/components">

    <ui:define name="title">Comptes</ui:define>

    <ui:define name="navigator">
        <sgbd:navigator comptes="active" />
    </ui:define>

    <ui:define name="content">
        <h:form>
            <h2>Connexion MySQL</h2>
            <h:outputText value="Base #{compteBean.current.name}" />
            <h:commandLink action="#{mySqlConnect.deconnectFromWeb()}">
                <h:graphicImage library="images" name="disconnect.gif" alt="Déconnexion" />
            </h:commandLink>
            <br /><br />
            <rich:panel header="Administrateur">
                <rich:tabPanel switchType="client">
                     <rich:tab header="Sauvegarde">
                        <h3>Sauvegarde à froid de la base de données</h3>
                        <h:panelGrid columns="4">
                            <h:outputText value="Chemin où sauvegarder les fichiers " />
                            <h:inputText value="#{mySqlConnect.backupColdPath}"
                                         required="true"
                                         requiredMessage="Veuillez indiquer un chemin de sauvegarde des fichiers"
                                         id="backupColdPathMySql" />
                            <rich:message for="backupColdPathMySql" ajaxRendered="true" />
                            <h:panelGroup />
                            
                            <h:outputText value="Nom du service MySQL " />
                            <h:inputText value="#{mySqlConnect.nameService}"
                                         required="true"
                                         requiredMessage="Veuillez indiquer le nom du service MySQL"
                                         id="nameServiceMySql" />
                            <rich:message for="nameServiceMySql" ajaxRendered="true" />
                            
                            <h:commandLink action="#{mySqlConnect.saveBackupColdScript()}">
                            <h:graphicImage library="images"
                                            name="save.png" />
                        </h:commandLink>
                        </h:panelGrid>
                        
                     </rich:tab>
                    <rich:tab header="Mémoire">
                        <h3>Mémoire</h3>
                        <rich:dataTable value="#{mySqlConnect.sizeByDatabase}"
                                        var="sizeByDatabase"
                                        rowClasses="even,odd"
                                        styleClass="dataTable">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{sizeByDatabase.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Size (Ko)" />
                                </f:facet>
                                <h:outputText value="#{sizeByDatabase.size}" />
                            </rich:column>
                        </rich:dataTable>
                    </rich:tab>
                    <rich:tab header="Tablespaces">
                        <h3>Tablespaces</h3>
                        <rich:dataTable value="#{mySqlConnect.allTablespaces}"
                                        var="tablespace"
                                        styleClass="dataTable"
                                        rowClasses="even,odd">
                            <f:facet name="noData">
                                Aucune donnée.
                            </f:facet>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{tablespace.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Engine" />
                                </f:facet>
                                <h:outputText value="#{tablespace.engine}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Type" />
                                </f:facet>
                                <h:outputText value="#{tablespace.type}" />
                            </rich:column>                            
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Extent size" />
                                </f:facet>
                                <h:outputText value="#{tablespace.extentSize}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Autoextend Size" />
                                </f:facet>
                                <h:outputText value="#{tablespace.autoExtendSize}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Maximum size" />
                                </f:facet>
                                <h:outputText value="#{tablespace.maximumSize}" />
                            </rich:column>
                        </rich:dataTable>
                    </rich:tab>
                    <rich:tab header="Instances">
                        <h3>Instances</h3>
                    </rich:tab>
                    <rich:tab header="Utilisateurs">
                        <h3>Utilisateurs et leurs caractéristiques</h3>
                        <rich:dataTable value="#{mySqlConnect.allUser}" 
                                        var="userMySql"
                                        rowClasses="even,odd"
                                        styleClass="dataTable">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{userMySql.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Host" />
                                </f:facet>
                                <h:outputText value="#{userMySql.host}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Max questions" />
                                </f:facet>
                                <h:outputText value="#{userMySql.maxQuestions}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Max updates" />
                                </f:facet>
                                <h:outputText value="#{userMySql.maxUpdates}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Max connections" />
                                </f:facet>
                                <h:outputText value="#{userMySql.maxConnections}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Max user connections" />
                                </f:facet>
                                <h:outputText value="#{userMySql.maxUserConnections}" />
                            </rich:column>                            
                        </rich:dataTable>
                        <br/>
                        <h3>Utilisateurs et leurs objets</h3>
                        <h3>Utilisateurs et rôles</h3>
                        <h4>La notion de rôle n'existe pas sous MySQL</h4>
                        <h3>Utilisateurs et privilèges</h3>
                        <rich:dataTable value="#{mySqlConnect.allUser}" 
                                        var="userMySql"
                                        rowClasses="even,odd"
                                        styleClass="dataTable">
                            <f:facet name="header">
                                <rich:columnGroup>
                                    <rich:column>
                                        <h:outputText value="Utilisateur"/>
                                    </rich:column>
                                    <rich:column breakRowBefore="true"
                                                 colspan="1">
                                        <h:outputText value="Privileges"/>
                                    </rich:column>
                                </rich:columnGroup>
                            </f:facet>
                            <rich:column>
                                <rich:collapsibleSubTableToggler for="privilegesByUser" />
                                <h:outputText value="#{userMySql.name}" />
                            </rich:column>
                            <rich:collapsibleSubTable value="#{userMySql.privileges}" 
                                                      var="privileges"
                                                      expanded="#{false}"
                                                      id="privilegesByUser" 
                                                      expandMode="client">
                                <rich:column colspan="1">
                                    <h:outputText value="#{privileges}" />
                                </rich:column>
                            </rich:collapsibleSubTable>
                        </rich:dataTable>
                    </rich:tab>
                    <rich:tab header="Autres bases de données">
                        <h3>Les autres base de données</h3>
                        <rich:dataTable value="#{mySqlConnect.allDataBases}"
                                        var="databasesMySql"
                                        styleClass="dataTable"
                                        rowClasses="even,odd">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Database" />
                                </f:facet>
                                <h:outputText value="#{databasesMySql}" />
                            </rich:column>
                        </rich:dataTable>
                    </rich:tab>
                </rich:tabPanel>
            </rich:panel>
        </h:form>
    </ui:define>
</ui:composition>